Repository navigation
docs: add CancellationToken propagation guide - #8148
Closed
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Closed
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Conversation
Added documentation showing how to propagate CancellationToken through nested tools using cancellation_token parameter and cancellation_token.link_future(). Fixes microsoft#8091
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new docs section includes a misleading first example and a non-runnable second example, and it does not yet demonstrate a deterministic cancellation result as required by the linked issue.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a new documentation section to the AgentChat migration guide explaining how to propagate autogen_core.CancellationToken so cancellation is observed across nested tool operations.
Changes:
- Added a “CancellationToken Propagation Through Nested Tools” section to the migration guide.
- Documented two propagation patterns: accepting a
cancellation_tokenparameter and usingcancellation_token.link_future(). - Included example snippets illustrating both approaches.
File summaries
| File | Description |
|---|---|
python/docs/src/user-guide/agentchat-user-guide/migration-guide.md |
Adds a dedicated section describing CancellationToken propagation and providing example code patterns. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+317
to
+320
| async def slow_operation(duration: int, cancellation_token: CancellationToken) -> str: | ||
| # Forward the cancellation token to nested async operations | ||
| await asyncio.sleep(duration) # This will be cancelled when token is cancelled | ||
| return "Operation completed" |
Comment on lines
+328
to
+332
| async def custom_operation(cancellation_token: CancellationToken) -> str: | ||
| future = asyncio.ensure_future(some_async_work()) | ||
| cancellation_token.link_future(future) | ||
| result = await future | ||
| return result |
Comment on lines
+335
to
+336
| When the cancellation token is cancelled, the linked future will be cancelled, | ||
| causing the `await` to raise `CancelledError`. |
Author
|
Superseded by #8184 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8091
Added documentation showing how to propagate CancellationToken through nested tools using cancellation_token parameter and cancellation_token.link_future().
Changes
Test plan